package cn.csdj.sism.web;

import cn.csdj.sism.pojo.Payment;
import cn.csdj.sism.service.PaymentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李加
 * 2023/4/10
 */
@CrossOrigin
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public List<Payment> selectPmAll(){
        return paymentService.selectPmAll();
    }

    /**
     * 通过Id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Payment selectPmById(@PathVariable Integer id){
        return paymentService.selectPmById(id);
    }
    /**
     * 添加
     * @param payment
     */
    @PostMapping
    public int insertPm(@RequestBody Payment payment){
        //如果为空就是添加
        if (StringUtils.isEmpty(payment.getPaymentId())){
            return paymentService.insertPm(payment);
        }else {
//            如果有值就是修改
            return paymentService.updatePm(payment);
        }

    }

    /**
     * 修改
     * @param payment
     */
    @PutMapping
    public int updatePm(@RequestBody Payment payment){
       return paymentService.updatePm(payment);
    }

    /**
     * 删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public int delectPm(@PathVariable Integer id){
       return paymentService.delectPmById(id);
    }

    @GetMapping("/page/{current}/{pageSize}")
    public IPage<Payment> selectPage(@PathVariable Integer current,@PathVariable Integer pageSize){
        return paymentService.selectPage(current,pageSize);
    }
}
